package com.lipeng.controller;

import com.lipeng.bean.Comment;
import com.lipeng.bean.Photo;
import com.lipeng.service.CommentService;
import com.lipeng.service.PhotoService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * Created by dllo on 18/3/8.
 */
@Controller
public class CommentController {
    @Resource
    private CommentService commentService;

    @RequestMapping(value = "commentlist")
    public String commentList(){
        return "commentlist";
    }

    @RequestMapping(value = "commentsearch")
    public String commentSearch(){
        return "commentsearch";
    }

    @ResponseBody
    @RequestMapping(value = "allcomment")
    public List<Comment> findAllComment(){
        return commentService.findAllComment();
    }

    @ResponseBody
    @RequestMapping(value = "searchcommentcontent")
    public List<Comment> selectCommentByContent(@RequestParam("comcontent") String content){
        return commentService.selectCommentByContent(content);
    }


    @RequestMapping(value = "delcomment")
    public String deleteCommentById(HttpServletRequest request, @RequestParam("comid")Integer comid){
        int result = commentService.deleteCommentById(comid);
        if (result > 0) {
            request.getSession().setAttribute("success", "success");
        } else {
            request.getSession().setAttribute("fail", "fail");
        }
        return "redirect:commentlist";
    }
}
